import { GetAttrInfoListUrl, GetDeleteInfo } from '@/api/product/attr'
export default {
  state: {
    attrList: [],
    id: undefined,
    attrName: '',
    attrValueList: []
  },
  mutations: {
    UPDATE_ATTRVALUELIST(state, attrInfoList) {
      state.attrList = attrInfoList
    },
    UPDATE_ATTRVALUE(state, obj) {
      state.id = obj.id
      state.attrName = obj.attrName
      state.attrValueList = obj.attrValueList
    }
  },
  actions: {
    async getAttrInfoList(
      { commit },
      { category1Id, category2Id, category3Id }
    ) {
      const result = await GetAttrInfoListUrl({
        category1Id,
        category2Id,
        category3Id
      })
      if (result.code === 200) {
        commit('UPDATE_ATTRVALUELIST', result.data)
      }
    },
    async deleteAttrInfo({ commit }, attrId) {
      const result = await GetDeleteInfo(attrId)
      if (result.code === 200) {
        return 'ok'
      } else {
        return Promise.reject('fail')
      }
    }
  }
}
